<?php
/**
 * Zend_Service_Netflix_Person class.
 *
 * @author Armando Padilla, armando_padilla_81@yahoo.com
 * @package Zend_Service_Netflix
 */ 
require_once "Utils.php";

class Zend_Service_Netflix_Person {

	/**
	 * Person Id.
	 *
	 * @var String
	 */
	public $id;
	
	/**
	 * Full Name of Person.
	 *
	 * @var String 
	 */
	public $name;
	
	/**
	 * Bio.
	 *
	 * @var String
	 */
	public $bio;
	
	/**
	 * List of Films person was part of.
	 *
	 * @var Array
	 */
	public $filmography = array();
	
	/**
	 * Netflix URL to Person's Page.
	 *
	 * @var String
	 */
	public $netflixProfilePage;
	
	
	/**
	 * Constructor
	 *
	 */
	public function __construct(){}
	
	
	
	/**
	 * Load the catalog data from XML.
	 *
	 * @param SimpleXMLElement $simpleXmlObject
	 */
	public function loadXML(SimpleXMLElement $simpleXmlObject){
		
		//Set all properties
		$this->id 	= Zend_Service_Netflix_Utils::parsePersonId((string)$simpleXmlObject->id);
		$this->name = (string)$simpleXmlObject->name;
		$this->bio  = (string)$simpleXmlObject->bio;
		
		//Set xml for Xpath use.
		$xml = simplexml_load_string($simpleXmlObject->asXML());
		
		//Get the Netflix profile.
		$webPage = $xml->xpath("link[@title='web page']");
		if(isset($webPage[0])){
			$this->netflixProfilePage = (string)$webPage[0]['href'];
		}
	
		//Get all the films
		$filmography = $xml->xpath("link[@title='filmography']/filmography/link");
		
		foreach($filmography as $film){
			
			$id    = Zend_Service_Netflix_Utils::parseTitleId((string)$film['href']);
			$title = (string)$film['title'];
			
			array_push($this->filmography, array("id"    => $id, 
												 "title" => $title));
			
		}
		
		
	}
	
	
}